//package vip.xiaonuo.vein.websocket;
//
//import io.netty.channel.*;
//import io.netty.handler.codec.http.*;
//import lombok.extern.slf4j.Slf4j;
//
///**
// * Http请求处理handler
// *
// * @create 2021-01-18 10:55
// */
//@Slf4j
//public class HttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
//
//    private final String wsUrl;
//
//    public HttpRequestHandler(String wsUrl) {
//        this.wsUrl = wsUrl;
//    }
//
//    @Override
//    protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
//        //如果发送的是到websocket端点的连接，则传递给下一个Handler
//        if (wsUrl.contains(request.uri())) {
//            ctx.fireChannelRead(request.retain());
//        } else {
//            if (HttpUtil.is100ContinueExpected(request)) {
//                send100Continue(ctx);
//            }
//
//            DefaultHttpResponse response = new DefaultHttpResponse(request.protocolVersion(), HttpResponseStatus.OK);
//            response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain;charset=UTF-8");
//            boolean keepAlive = HttpUtil.isKeepAlive(request);
//            if (keepAlive) {
//                response.headers()
//                        .set(HttpHeaderNames.CONTENT_LENGTH, 1024 * 10)
//                        .set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
//            }
//            ctx.write(response);
//
//            ChannelFuture channelFuture = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
//            if (!keepAlive){
//                //如果不是keep-Alive连接，则在发送完一次response后关闭channel
//                channelFuture.addListener(ChannelFutureListener.CLOSE);
//            }
//        }
//    }
//
//    private static void send100Continue(ChannelHandlerContext ctx) {
//        DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE);
//        ctx.writeAndFlush(response);
//    }
//
//    @Override
//    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
//        log.error("caught exception:",cause);
//        ctx.close();
//    }
//}